package com.tang.login_jwt.controller;

import com.tang.login_jwt.entity.User;
import com.tang.login_jwt.service.IUserService;
import com.tang.login_jwt.util.JwtUtil;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class JwtController {

    private final IUserService userService;

    public JwtController(IUserService userService) {
        this.userService = userService;
    }

    @PostMapping("/login")
    public String login(@RequestBody User user) {
        if ("admin".equals(user.getUsername()) && "admin".equals(user.getPassword())) {
            return JwtUtil.generate(user.getUsername());
        }
        return "账号密码错误！";
    }

    @GetMapping("/api")
    public String api() {
        userService.doSomeThing();
        return "API数据返回成功";
    }

    @GetMapping("/api2")
    public String api2() {
        return "API2数据返回成功";
    }

}
